﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using ChuckNorris.Models;
using ImpromptuInterface.MVVM;


namespace ChuckNorris.ViewModels
{
    public class MainViewModel : ImpromptuViewModel
    {
        private readonly IWebService _service;

        public MainViewModel(IWebService service)
        {
            _service = service;
            _service.DataRetrieved += (sender, e) =>
            {
                SetBusy(false);
                Dynamic.Data = _service.Data;
            };

            SetBusy(false);
            Dynamic.Title = "Impromptu MVVM Sample";
            Dynamic.Name = "Service: " + _service.Name;
        }

        public void LoadData()
        {
            SetBusy(true);
            _service.LoadData();
        }

        private void SetBusy(bool busy)
        {
            if (busy)
            {
                Dynamic.ButtonVisibility = Visibility.Collapsed;
                Dynamic.BusyVisibility = Visibility.Visible;
            }
            else
            {
                Dynamic.ButtonVisibility = Visibility.Visible;
                Dynamic.BusyVisibility = Visibility.Collapsed;
            }
        }
    }
}
